package com.dg11185.nearshop.net.entity;

import org.json.JSONObject;

import com.dg11185.libs.ormlite.field.DatabaseField;
import com.dg11185.libs.ormlite.table.DatabaseTable;
import com.dg11185.nearshop.db.entity.DbConstant;

/**
 * @author : daibo
 * @version : 2014-5-15 下午9:22:38
 * @see :
 */
@DatabaseTable(tableName = DbConstant.AREA)
public class Area {

    /** 数据库需要用到的自增主键，用于删除数据 */
    @DatabaseField(generatedId = true)
    private int id;

    @DatabaseField(width = 10)
    public String areaId = "";

    @DatabaseField(width = 10)
    public String name = "";

    @DatabaseField(width = 10)
    public String postNum = "";

    @DatabaseField(width = 20)
    public String areaNum = "";

    @DatabaseField(width = 20)
    public String parentId = "";

    @DatabaseField(width = 10)
    public double latitude;

    @DatabaseField(width = 10)
    public double longitude;

    
    public Area() {

    }

    public void parseEntity(JSONObject object) {
        areaId = object.optString("id");
        name = object.optString("name");
        postNum = object.optString("postNum");
        areaNum = object.optString("areaNum");
        parentId = object.optString("parentId");
        
        if("null".equals(object.optString("lat")) || "".equals(object.optString("lat",""))){
            latitude = .0f;
        }else{
            latitude = Double.parseDouble(object.optString("lat", "0.0"));
        }
        if("null".equals(object.optString("lng")) || "".equals(object.optString("lng",""))){
            longitude = .0f;
        }else{
            longitude = Double.parseDouble(object.optString("lng", "0.0"));
        }
    }

}
